﻿
function cssToHex (input) {
	var pattern:RegExp=/\#/g;
	input=input.replace(pattern,"0x");
	return input;
}
function d2h( d:int ) : String { //decimal to hex, as found at: http://goflashgo.wordpress.com/2007/03/28/simple-actionscript-hex2decdec2hex-methods/
	var c:Array = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ];
	if( d > 255 ) d = 255;
	var l:int = d / 16;
	var r:int = d % 16;
	return c[l]+c[r];
}


//CREATE THE COLOURED OBJECTS  
function setupColors(backgroundColor, resultsColor, catColor) {
	backgroundColor = cssToHex (backgroundColor);
	resultsColor = cssToHex (resultsColor);
	catColor = cssToHex (catColor);
	//overall background
	var square:Shape = new Shape();
	square.graphics.beginFill(backgroundColor, 1);
	square.graphics.drawRect(0-((toolWidth-200)/2),  0-((toolHeight-400)/2), toolWidth, toolHeight);
	square.graphics.endFill();
	this.addChild(square);
	this.setChildIndex(square, 0);
	//everything else
	for (var catHeadName:String in CategoriesArray) {
		if (catHeadName=="Results") {
			formColors(CategoriesArray[catHeadName].object, backgroundColor, resultsColor);
		} else {
			formColors(CategoriesArray[catHeadName].object, backgroundColor, catColor);
		}
	}
}

//Creates the custom shapes for the specified category object
function formColors(object:Object, bgColor:int, catbarColor:uint) {
	//this creates the background sized square that is in every instance
	//of the category object
	var square:Shape = new Shape();
	square.graphics.beginFill(bgColor, 1);
	square.graphics.drawRect(0-((toolWidth-200)/2), 0-((toolHeight-400)/2), toolWidth, toolHeight);
	square.graphics.endFill();
	square.y=(-toolTop);
	object.bgRect.addChild(square);

	//this creates the category header
	//object.backg.setChildIndex (square, 0) 
	var bar:Shape = new Shape();
	bar.graphics.beginFill(catbarColor, 1);
	bar.graphics.drawRect(0-((toolWidth-200)/2), 0, toolWidth, 15);
	bar.graphics.endFill();
	object.catBar.catColor.addChild(bar);
}